<?php
/**
 *房源
 */

namespace app\admin\controller;

use app\common\controller\AdminController;
use think\Exception;
use app\admin\model\House as HouseModel;
use custom\Err;
use custom\Redis;

class Export extends AdminController {
    protected $headersFields = [];

    public $notNeedToken = ['*'];


    /**
     * 房源导出
     * @return false|string
     */
    public function exportHouse() {
        try {
            $params = $this->checkParams('key');
            $key = base64_decode($params['key']);
            $key = substr($key, 16);
            $redisModel = Redis::getInstance();
            $data = $redisModel->get($key);
            if (empty($data)) {
                $this->resErr('请重新操作');
            }
            $data = json_decode($data, true);
            exportCsv($data['data'], $data['title']);
        } catch (Exception $e) {
            return $this->resErr('请重新操作');
        }
    }


}
